//
//  FirstStepController.m
//  GroceryStoryboards
//
//  Created by jose on 11/03/13.
//  Copyright (c) 2013 Jose Luis Lopez. All rights reserved.
//

#import "FirstStepController.h"

@interface FirstStepController ()

@end

@implementation FirstStepController

@synthesize nameString, nameTextField;

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.nameString = @"";
    
}

#pragma mark - TextField management


- (BOOL)textFieldShouldReturn:(UITextField *)textField {
    
    if ([textField.text length] > 0) {
        
        // We hide the keyboard
        [textField resignFirstResponder];
        
        if ([self.parentViewController respondsToSelector:@selector(nextStep)])
            [self.parentViewController performSelector:@selector(nextStep)];
        
        return YES;
    } else
        return NO;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    

    // Make the string that is currently displayed
    if ([string isEqualToString:@""])
        self.nameString = [textField.text substringToIndex:[textField.text length] - 1];
    else
        self.nameString = [textField.text stringByAppendingString:string];
    
    // Inform to the parent for displaying it
    if ([self.parentViewController respondsToSelector:@selector(typingString:)])
        [self.parentViewController performSelector:@selector(typingString:) withObject:self.nameString];
    
    return YES;
}

#pragma mark Scroll Control

- (void)hideControls {
    [nameTextField resignFirstResponder];
}

- (void)showControls {
    [nameTextField becomeFirstResponder];
}

@end
